import { lazyReportBatch } from "../report";
export default function observerLCP() {
  const entryHandler = (list) => {
    if (observerr) {
      observerr.disconnect();
    }

    for (const entry of list.getEntries()) {
      const json = entry.toJSON();
      console.log(json);
      const reportData = {
        ...json,
        type: "performance",
        pageUrl: window.location.href,
        subType: entry.name,
        pageUrl: window.location.href,
      };

      // 发送数据 todo
      console.log(reportData);
      lazyReportBatch(reportData);
    }
  };

  // 统计和计算fp的时间
  const observerr = new PerformanceObserver(entryHandler);

  // buffered: true 确保观测到所有paint时间
  observerr.observe({ type: "largest-contentful-paint", buffered: true });
}
